﻿using System.Data;

namespace clock
{
    public delegate void ClockEventHandler(object sender, ClockEventArgs args);

    public class ClockEventArgs : EventArgs
    {
        public DateTime Time { get; set; }
    }

    public class Clock
    {
        public event ClockEventHandler Tick;
        public event ClockEventHandler Alarm;

        private DateTime alarmTime;

        public void SetAlarm(DateTime time)
        {
            alarmTime = time;
        }

        public void Run()
        {
            while (true)
            {
                Thread.Sleep(1000);
                if (DateTime.Now >= alarmTime)
                {
                    Alarm(this, new ClockEventArgs { Time = DateTime.Now });
                    break;
                }
                else
                {
                    Tick(this, new ClockEventArgs { Time = DateTime.Now});
                }
            }
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            var clock = new Clock();
            clock.Tick += OnTick;
            clock.Alarm += OnAlarm;
            clock.SetAlarm(DateTime.Now.AddSeconds(5));
            clock.Run();
        }

        private static void OnTick(object sender, ClockEventArgs args)
        {
            Console.WriteLine($"Tick: {args.Time}");
        }

        private static void OnAlarm(object sender, ClockEventArgs args)
        {
            Console.WriteLine($"Alarm: {args.Time}");
        }
    }
}